import asyncio
import time

start = time.time()
urls = [
    'www.1.com', 'www.2.com', 'www.3.com'
]


async def get_request(url):
    print('正在请求：', url)
    await asyncio.sleep(2)
    print('请求结束:', url)


# 有了三个任务对象和一个事件循环对象
if __name__ == '__main__':
    tasks = []
    for url in urls:
        c = get_request(url)
        task = asyncio.ensure_future(c)
        tasks.append(task)
    # 将三个任务对象，添加到一个事件循环对象中
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.wait(tasks))

    print('总耗时:', time.time() - start)
